package biz.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "bbs_board")
public class BbsBoard implements Serializable {

	private static final long serialVersionUID = 1L;
	private String id;
	private String boardname;
	private String summary;
	private String supersetid;
//	private BbsBoard boardb;
	private List<BbsBoard> selfboard;
	private int postsize;
	private int isdisplay;
	//private String masterid;
	private BbsUser boarduser;
	private String postkey;
	private String orderby;
	private List<BbsPost> postlist;
	private List<BbsAttachment> attlist;
//	private List<BoardTemplate> tempList;
	private int posttaday;
	private int topiccount;
	private BbsPost postlatest;
	
	@Id
	@GeneratedValue(generator = "pk")
	@GenericGenerator(name = "pk", strategy = "uuid.hex")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getBoardname() {
		return boardname;
	}

	public void setBoardname(String boardname) {
		this.boardname = boardname;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getSupersetid() {
		return supersetid;
	}

	public void setSupersetid(String supersetid) {
		this.supersetid = supersetid;
	}
	
////////
//	@OneToMany(mappedBy="supersetid", cascade = CascadeType.REFRESH)
	@Transient
	public List<BbsBoard> getSelfboard() {
		return selfboard;
	}

	public void setSelfboard(List<BbsBoard> selfboard) {
		this.selfboard = selfboard;
	}

//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumn(name = "supersetid")
//	public BbsBoard getBoardb() {
//		return boardb;
//	}
//
//	public void setBoardb(BbsBoard boardb) {
//		this.boardb = boardb;
//	}
////////
	@Transient
	public int getPostsize() {
		return postsize;
	}

	public void setPostsize(int postsize) {
		this.postsize = postsize;
	}


	public int getIsdisplay() {
		return isdisplay;
	}

	public void setIsdisplay(int isdisplay) {
		this.isdisplay = isdisplay;
	}

//	public String getMasterid() {
//		return masterid;
//	}
//
//	public void setMasterid(String masterid) {
//		this.masterid = masterid;
//	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "masterid")
	public BbsUser getBoarduser() {
		return boarduser;
	}

	public void setBoarduser(BbsUser boarduser) {
		this.boarduser = boarduser;
	}
	
	public String getPostkey() {
		return postkey;
	}

	public void setPostkey(String postkey) {
		this.postkey = postkey;
	}

	@OneToMany(mappedBy="board", cascade = CascadeType.REFRESH)
	@OrderBy(value = "date desc")
	public List<BbsPost> getPostlist() {
		return postlist;
	}

	public void setPostlist(List<BbsPost> postlist) {
		this.postlist = postlist;
	}

	public String getOrderby() {
		return orderby;
	}

	public void setOrderby(String orderby) {
		this.orderby = orderby;
	}

	@OneToMany(mappedBy="attboard", cascade = CascadeType.REFRESH)
	@OrderBy(value = "date desc")
	public List<BbsAttachment> getAttlist() {
		return attlist;
	}

	public void setAttlist(List<BbsAttachment> attlist) {
		this.attlist = attlist;
	}

	@Transient
	public int getPosttaday() {
		return posttaday;
	}

	public void setPosttaday(int posttaday) {
		this.posttaday = posttaday;
	}

	@Transient
	public BbsPost getPostlatest() {
		return postlatest;
	}

	public void setPostlatest(BbsPost postlatest) {
		this.postlatest = postlatest;
	}
	
	@Transient
	public int getTopiccount() {
		return topiccount;
	}

	public void setTopiccount(int topiccount) {
		this.topiccount = topiccount;
	}

	public int hashCode()
	{
		return new HashCodeBuilder().append(getId()).toHashCode();
	}

	public String toString()
	{
		return new ToStringBuilder(this).append("id", getId()).toString();
	}

	public boolean equals(Object other)
	{
		if (this == other)
		{
			return true;
		}
		if (!(other instanceof BbsBoard))
		{
			return false;
		}
		BbsBoard castOther = (BbsBoard) other;
		return new EqualsBuilder().append(this.getId(), castOther.getId()).isEquals();
	}
}
